<h1><?php __('Users'); ?></h1>

<ul class="options">
    <li><?php
    echo $html->link(
        $html->image('icons/user--plus.png').' '.__('Add a new user', true),
        array(
            'action' => 'add',
            'admin' => true
        ),
        array('escape' => false)
    );
    ?></li>
</ul>

<div class="box table">

    <?php
    $paginator->options(array(
        'url' => array(
            'admin' => true
        )
    ));
    $sortField = $paginator->sortKey();
    $sortImage = $paginator->sortDir() == 'asc'
               ? $html->image('icons/sort-alphabet.png', array('alt' => __('Ascending', true)))
               : $html->image('icons/sort-alphabet-descending.png', array('alt' => __('Descending', true)));
    $blankImage = $html->image('icons/blank.gif');
    ?>

    <table>
        <thead>
            <tr>
                <th><?php
                echo $paginator->sort(__('Username', true), 'username');
                if ($sortField === 'AgencyUser.username'): echo $sortImage;
                else: echo $blankImage;
                endif;
                ?></th>
                <th><?php
                echo $paginator->sort(__('Name', true), 'name');
                if ($sortField === 'AgencyUser.name'): echo $sortImage;
                else: echo $blankImage;
                endif;
                ?></th>
                <th><?php
                echo $paginator->sort(__('Email', true), 'email');
                if ($sortField === 'AgencyUser.email'): echo $sortImage;
                else: echo $blankImage;
                endif;
                ?></th>
                <th><?php
                echo $paginator->sort(__('Status', true), 'can_log_in');
                if ($sortField === 'AgencyUser.can_log_in'): echo $sortImage;
                else: echo $blankImage;
                endif;
                ?></th>
                <th><?php
                echo $paginator->sort(__('Added', true), 'created');
                if ($sortField === 'AgencyUser.created'): echo $sortImage;
                else: echo $blankImage;
                endif;
                ?></th>
            </tr>
        </thead>
        <tbody>
            <?php foreach ($agencyUsers as $agencyUser): ?>
            <tr>
                <td><?php
                echo $html->link(
                    $agencyUser['AgencyUser']['username'],
                    array(
                        'action' => 'edit',
                        $agencyUser['AgencyUser']['id'],
                        'admin' => true
                    ),
                    array(
                        'title' => __('Edit user', true)
                    )
                );
                ?></td>
                <td><?php
                echo $agencyUser['AgencyUser']['name'];
                ?></td>
                <td><?php
                echo $agencyUser['AgencyUser']['email'];
                ?></td>
                <td><?php
                $agencyUser['AgencyUser']['can_log_in']
                     ? __('Active')
                     : __('Disabled');
                ?></td>
                <td><?php
                echo strftime(
                    '%x', strtotime($agencyUser['AgencyUser']['created'])
                );
                ?></td>
            </tr>
            <?php endforeach; ?>
        </tbody>
    </table>

    <div class="pagination">
    
        <div class="prev">
            <?php
            echo $paginator->prev(
                $html->image('icons/control-180.png') . __('Previous', true),
                array('escape' => false)
            );
            ?>
        </div>
    
        <div class="next">
            <?php
            echo $paginator->next(
                __('Next', true) . $html->image('icons/control.png'),
                array('escape' => false)
            );
            ?>
        </div>
    
        <?php
        echo $paginator->counter(array(
            'format' => __('Page %page% of %pages%', true)
        ));
        ?>
    
    </div>

</div>